package com.jhgsys.internal.incentive.controller;

import com.jhgsys.internal.common.annotation.Log;
import com.jhgsys.internal.common.controller.BaseController;
import com.jhgsys.internal.common.entity.FebsConstant;
import com.jhgsys.internal.common.entity.FebsResponse;
import com.jhgsys.internal.common.entity.QueryRequest;
import com.jhgsys.internal.common.entity.FebsConstant;
import com.jhgsys.internal.common.exception.FebsException;
import com.jhgsys.internal.common.utils.FebsUtil;
import com.jhgsys.internal.incentive.entity.IncentiveGoodsOrderDtl;
import com.jhgsys.internal.incentive.service.IIncentiveGoodsOrderDtlService;
import com.wuwenze.poi.ExcelKit;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;
import java.util.Map;
import javax.validation.constraints.NotBlank;
import java.util.Date;

/**
 * 安全奖励订单明细 Controller
 *
 * @author zhangwei
 * @date 2024-09-02 11:28:11
 */
@Slf4j
@Validated
@Controller
public class IncentiveGoodsOrderDtlController extends BaseController {

    @Autowired
    private IIncentiveGoodsOrderDtlService incentiveGoodsOrderDtlService;

    @GetMapping(FebsConstant.VIEW_PREFIX + "incentiveGoodsOrderDtl")
    @RequiresPermissions("incentiveGoodsOrderDtl:view")
    public String incentiveGoodsOrderDtlIndex(){
        return FebsUtil.view("incentive/incentiveGoodsOrderDtl/incentiveGoodsOrderDtlList");
    }

    @GetMapping(FebsConstant.VIEW_PREFIX + "incentiveGoodsOrderDtl/add")
    @RequiresPermissions("incentiveGoodsOrderDtl:add")
    public String incentiveGoodsOrderDtlAdd(){
        return FebsUtil.view("incentive/incentiveGoodsOrderDtl/incentiveGoodsOrderDtlEdit");
    }

    @GetMapping(FebsConstant.VIEW_PREFIX + "incentiveGoodsOrderDtl/update/{id}")
    @RequiresPermissions("incentiveGoodsOrderDtl:edit")
    public String incentiveGoodsOrderDtlUpdate(Model model, @PathVariable("id") String id){
        model.addAttribute("incentiveGoodsOrderDtl", incentiveGoodsOrderDtlService.findIncentiveGoodsOrderDtlById(id));
        return FebsUtil.view("incentive/incentiveGoodsOrderDtl/incentiveGoodsOrderDtlEdit");
    }

    /**
     * 查询（所有）
     * @author zhangwei
     * @date 2024-09-02 11:28:11
     */
    @GetMapping("incentiveGoodsOrderDtl")
    @ResponseBody
    @RequiresPermissions("incentiveGoodsOrderDtl:view")
    public FebsResponse getAllIncentiveGoodsOrderDtls(IncentiveGoodsOrderDtl incentiveGoodsOrderDtl) {
        return new FebsResponse().success().data(incentiveGoodsOrderDtlService.findIncentiveGoodsOrderDtlList(incentiveGoodsOrderDtl));
    }

    /**
     * 查询（分页）
     * @author zhangwei
     * @date 2024-09-02 11:28:11
     */
    @GetMapping("incentiveGoodsOrderDtl/list")
    @ResponseBody
    @RequiresPermissions("incentiveGoodsOrderDtl:view")
    public FebsResponse incentiveGoodsOrderDtlList(QueryRequest request, IncentiveGoodsOrderDtl incentiveGoodsOrderDtl) {
        Map<String, Object> dataTable = getDataTable(this.incentiveGoodsOrderDtlService.findIncentiveGoodsOrderDtlPage(request, incentiveGoodsOrderDtl));
        return new FebsResponse().success().data(dataTable);
    }

    /**
     * 新增 IncentiveGoodsOrderDtl
     * @author zhangwei
     * @date 2024-09-02 11:28:11
     */
    @Log("新增IncentiveGoodsOrderDtl")
    @PostMapping("incentiveGoodsOrderDtl")
    @ResponseBody
    @RequiresPermissions("incentiveGoodsOrderDtl:add")
    public FebsResponse addIncentiveGoodsOrderDtl(@Valid IncentiveGoodsOrderDtl incentiveGoodsOrderDtl) throws FebsException {
        try {
            incentiveGoodsOrderDtl.setCreatedBy(getCurrentUser().getUserName());
            this.incentiveGoodsOrderDtlService.createIncentiveGoodsOrderDtl(incentiveGoodsOrderDtl);
            return new FebsResponse().success();
        } catch (Exception e) {
            String message = "新增IncentiveGoodsOrderDtl失败";
            log.error(message, e);
            throw new FebsException(message);
        }
    }

    /**
     * 逻辑删除 IncentiveGoodsOrderDtl
     * @author zhangwei
     * @date 2024-09-02 11:28:11
     */
    @Log("逻辑删除IncentiveGoodsOrderDtl")
    @GetMapping("incentiveGoodsOrderDtl/delete/{id}")
    @ResponseBody
    @RequiresPermissions("incentiveGoodsOrderDtl:delete")
    public FebsResponse deleteIncentiveGoodsOrderDtl(@PathVariable("id") String incentiveGoodsOrderDtlIds) throws FebsException {
        try {
            IncentiveGoodsOrderDtl incentiveGoodsOrderDtl = new IncentiveGoodsOrderDtl();
            incentiveGoodsOrderDtl.setDeletedBy(getCurrentUser().getUserName());
            incentiveGoodsOrderDtl.setDeletedTime(new Date());
            incentiveGoodsOrderDtl.setDeletedFlg(FebsConstant.INVALID);
            this.incentiveGoodsOrderDtlService.deleteIncentiveGoodsOrderDtl(incentiveGoodsOrderDtl,incentiveGoodsOrderDtlIds);
            return new FebsResponse().success();
        } catch (Exception e) {
            String message = "删除IncentiveGoodsOrderDtl失败";
            log.error(message, e);
            throw new FebsException(message);
        }
    }

    /**
    * 物理删除 IncentiveGoodsOrderDtl
    * @author zhangwei
    * @date 2024-09-02 11:28:11
    */
    @Log("物理删除IncentiveGoodsOrderDtl")
    @GetMapping("incentiveGoodsOrderDtl/physicallyDelete/{id}")
    @ResponseBody
    @RequiresPermissions("incentiveGoodsOrderDtl:delete")
    public FebsResponse physicallyDeleteIncentiveGoodsOrderDtl(@PathVariable("id") String incentiveGoodsOrderDtlIds) throws FebsException {
        try {
            this.incentiveGoodsOrderDtlService.physicallyDeleteIncentiveGoodsOrderDtl(incentiveGoodsOrderDtlIds);
            return new FebsResponse().success();
        } catch (Exception e) {
            String message = "删除IncentiveGoodsOrderDtl失败";
            log.error(message, e);
            throw new FebsException(message);
        }
    }

    /**
     * 修改 IncentiveGoodsOrderDtl
     * @author zhangwei
     * @date 2024-09-02 11:28:11
     */
    @Log("修改IncentiveGoodsOrderDtl")
    @PostMapping("incentiveGoodsOrderDtl/update")
    @ResponseBody
    @RequiresPermissions("incentiveGoodsOrderDtl:edit")
    public FebsResponse updateIncentiveGoodsOrderDtl(IncentiveGoodsOrderDtl incentiveGoodsOrderDtl) throws FebsException {
        try {
            incentiveGoodsOrderDtl.setUpdatedBy(getCurrentUser().getUserName());
            this.incentiveGoodsOrderDtlService.updateIncentiveGoodsOrderDtl(incentiveGoodsOrderDtl);
            return new FebsResponse().success();
        } catch (Exception e) {
            String message = "修改IncentiveGoodsOrderDtl失败";
            log.error(message, e);
            throw new FebsException(message);
        }
    }

}
